require('../css/login.less')
let uname = document.querySelector('.uname')
let pass = document.querySelector('.pass')
let unbtn = document.querySelector('ul li button')
uname.addEventListener('input',unamech)
function unamech() {
	if (window.utils.cellPhoneNumber(uname.value)) {
		uname.style.color = 'springgreen'
		return true
	} else {
		uname.style.color = 'red'
		return false
	}
}
pass.addEventListener('input', passch)
function passch() {
	if (window.utils.checkPhoneNum(pass.value)) {
		pass.style.color = 'springgreen'
		return true
	} else {
		pass.style.color = 'red'
		return false
	}
}
unbtn.addEventListener('click', function () {
	let flage = [unamech(),passch()]
	let arr = flage.every(function (item) {
		return item
	})
	if (arr === true) {
		window.$http.post(
			'/users/login',
			{
				account: uname.value,
				password: pass.value,
			},
			function (res) {
				if (res.status === 0) {
					localStorage.setItem('users', JSON.stringify(res.data.user))
					window.utils.showToast(0, res.msg, function () {
						window.location.href = `./index.html`
					})
				}else{
                    window.utils.showToast(1, res.msg)
                }
			}
		)
	}
})
